package com.woniu.command.matcommand;

import com.woniu.command.Command;
import com.woniu.command.handler.AppCommandHandler;
import com.woniu.command.handler.MatCommandHandler;
import com.woniu.outlet.po.ApplicationDetail;
import com.woniu.outlet.po.MaterialApplication;
import com.woniu.util.ApplicationContextHolder;
import com.woniu.util.SnowflakeIdGenerator;

import java.util.Date;

public class AddMatCommand implements Command<MaterialApplication> {
    private MatCommandHandler handler;

    public AddMatCommand ( ) {
        //ApplicationContextHolder.getApplicationContext()拿到ApplicationContext
        this.handler = ApplicationContextHolder.getApplicationContext()
                .getBean(MatCommandHandler.class);
    }

    @Override
    public void execute (MaterialApplication materialApplication) {
        materialApplication.setApplicationTime(new Date());
        String str = "App_"+SnowflakeIdGenerator.nextId();
        materialApplication.setApplicationCode(str);
        handler.addMaterialApplication(materialApplication);
    }
}
